﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Cinemax.DTO;
namespace Cinemax.DAO
{
    public class SuatChieuDAO
    {
        static rapphimDataContext data = new rapphimDataContext();

        public static List<SuatChieuDTO> getSuatChieuHomNay(int maPhim, DateTime ngayChieu)
        {
            List<SuatChieuDTO> listSuatChieu = new List<SuatChieuDTO>();
            List<SP_GET_SUATCHIEU_TU_MAPHIM_NGAYCHIEUResult> lSuatChieu = new List<SP_GET_SUATCHIEU_TU_MAPHIM_NGAYCHIEUResult>();
            lSuatChieu = data.SP_GET_SUATCHIEU_TU_MAPHIM_NGAYCHIEU(maPhim, ngayChieu).ToList();
            foreach (SP_GET_SUATCHIEU_TU_MAPHIM_NGAYCHIEUResult item in lSuatChieu)
            {
                SuatChieuDTO sc = new SuatChieuDTO(item);
                listSuatChieu.Add(sc);
            }
            return listSuatChieu;
        }

        public static void insertSuatChieu(int mphim, int mphong, DateTime tgbd, DateTime tgkt, int slv)
        {
            data.SP_INSERT_SUATCHIEU(mphim, mphong, tgbd, tgkt, slv);
        }

        public static SuatChieuDTO getSuatChieuByID(int id)
        {
            SuatChieuDTO sc = new SuatChieuDTO();
            SP_GET_SUATCHIEU_BYIDResult scid = new SP_GET_SUATCHIEU_BYIDResult();
            try
            {
                scid = data.SP_GET_SUATCHIEU_BYID(id).ElementAt(0);
            }
            catch (Exception)
            {
                scid = null;
                return null;
            }
            sc = new SuatChieuDTO(scid);

            return sc;
        }
    }
}